package com.qfedu.service.impl;

import com.qfedu.dao.SysUserMapper;
import com.qfedu.pojo.SysUser;
import com.qfedu.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service //@Service 实例化SysUserServiceImpl
public class SysUserServiceImpl implements SysUserService {
    @Autowired//根据类型自动注入对象
    private SysUserMapper userDao;

    //登录
    @Override
    public SysUser findByName(String tel, String password) {
        SysUser users = userDao.selectByTel(tel);
        if(users == null) {
            throw new RuntimeException("账户名不存在~");
        }
        if (!users.getPassword().equals(password)) {
            throw new RuntimeException("密码错误~");
        }
        return users;
    }

    //注册
    @Override
    public void addUser(SysUser user) {
        try {
            userDao.insert(user);
        }catch (Exception e){
            throw new RuntimeException("success！");
        }
    }

    //修改手机号
    @Override
    public void updateUserTel(SysUser user) {
        try {
            userDao.updateByPrimaryKeyTel(user);
        }catch (Exception e){
            throw new RuntimeException("success!");
        }
    }

    //修改邮箱
    @Override
    public void updateUserEmail(SysUser user) {
        try {
            userDao.updateByPrimaryKeyEmail(user);
        }catch (Exception e){
            throw new RuntimeException("success!");
        }
    }

    //修改密码
    @Override
    public void updateUserPassword(SysUser user) {
        try {
            userDao.updateByPrimaryKeyPassword(user);
        }catch (Exception e){
            throw new RuntimeException("success!");
        }
    }

}
